<template>
	<view class="store-pack">
		<block v-if="show">
			<view class="store-pack-list">
				<pt-product-items
					:showSort="false"
					:isBig="true"
					mode="aspectFill"
					:object="{goods_list: storePackList}"
					:isMerchant="true"
					:isPack="true"
					@GoInfoAddFoot="GoInfoAddFoot"
					:isLogin="isLogin">
				</pt-product-items>
			</view>
			<pt-loading-more v-if="isLoading"></pt-loading-more>
			<pt-nomore v-if="noMore && storePackList.length"></pt-nomore>
			<pt-nothing 
				text="暂无套餐" 
				v-if="noMore && !storePackList.length" 
				:fixed="true" 
				bgColor="#FFF"
				icon="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/nothing.png?v=1">
			</pt-nothing>
		</block>
		<pt-loading></pt-loading>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				storePackList: [],
				noMore: false,
				isLoading: false,
				page: 0,
				isLogin: false
			};
		},
		onLoad(options) {
			if(options.parent_id){
				uni.setStorageSync('parent_id',options.parent_id)
				// 如果用户从分享的小程序卡片点击进来的,设置一个url缓存,登录后返回当前缓存url
				let pages = getCurrentPages();
				let curPage = pages[pages.length - 1];
				uni.setStorageSync('newurl',curPage.$page.fullPath)
				this.$u.api.binding_refer({id: options.parent_id}).catch(() => {
					console.log('接口报错：绑定失败')
					// uni.showToast({
					// 	icon: 'none',
					// 	title: '绑定失败'
					// })
				})
			}
			this.getStorePack()
		},
		onShow() {
			if(uni.getStorageSync('userInfo')){
				this.isLogin = true
			}else{
				this.isLogin = false
			}
		},
		methods: {
			getStorePack(){
				this.$u.api.StoreGoodsList({
					type: 2,
					limit: 10,
					page: this.page,
					store_id: uni.getStorageSync('userInfo')?JSON.parse(uni.getStorageSync('userInfo')).store_id:1,
				}).then(res => {
					let user_id = uni.getStorageSync('userInfo')?JSON.parse(uni.getStorageSync('userInfo')).user_id:0
					this.$u.mpShare = {
						title: '套餐列表',
						path: '/merchant/store-pack/store-pack?parent_id=' + user_id
					}
					this.show = true
					this.isLoading = false
					if(res.datas.length){
						res.datas.forEach(item => {
							this.storePackList.push(item)
						})
					}else{
						this.noMore = true
					}
				})
			},
			GoInfoAddFoot(goods_id){
				this.addFoot('套餐-列表-详情','#客户查看了套餐，对贵公司的套餐感兴趣',goods_id)
			},
			addFoot(where,detail,goods_id){
				this.$u.api.AddFoot({
					// #ifdef MP-WEIXIN
					type: 1,
					// #endif
					// #ifdef APP-PLUS
					type: 2,
					// #endif
					// #ifdef H5
					type: 3,
					// #endif
					store_id: uni.getStorageSync('userInfo')?JSON.parse(uni.getStorageSync('userInfo')).store_id:'',
					client: 1,
					where: where,
					stay_time: 0,
					goods_id: 0,
					store_goods_id: goods_id?goods_id:0,
					is_new: 1,
					detail: detail?detail:''
				})
			},
		},
		onReachBottom() {
			if(!this.noMore){
				this.page++
				this.isLoading = true
				this.getStorePack()
			}
		}
	}
</script>

<style lang="scss">
	.store-pack{
		.store-pack-list{
			padding: 30rpx 30rpx 0;
			/deep/ .product-items{
				border-bottom: none;
			}
			/deep/ .product-items-list-item{
				margin-top: 0;
				box-shadow: 0px 20rpx 40rpx 0px rgba(40,34,31,0.05);
				border-radius: 0px 0px 8rpx 8rpx;
				margin-bottom: 60rpx;
				&:last-child{
					margin-bottom: 0;
				}
				image{
					height: 550rpx;
					border-radius: 8rpx 8rpx 0px 0px;
				}
			}
		}
	}
</style>
